#include <func.h>
#include "head.h"
int upload(char* argv, int sockFd){
    //puts file
    char arr[100] = "";
    strcpy(arr, argv);
    char* command = strtok(arr, " ");
    char* fileName = strtok(NULL, " ");
    int fd = open(fileName, O_RDWR);
    struct stat statbuf;
    fstat(fd, &statbuf);
    train_t t;
    t.dataLength = sizeof(statbuf.st_size);
    memcpy(t.buf, &statbuf.st_size, sizeof(statbuf.st_size));
    send(sockFd, &t, sizeof(t.dataLength) + t.dataLength, MSG_NOSIGNAL);//发送文件长度   
    char *p = (char *)mmap(NULL, statbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    send(sockFd, p, statbuf.st_size, MSG_NOSIGNAL);  
    munmap(p, statbuf.st_size);
    close(fd);
}